package com.xunyin.modules.device.service.impl;

import com.github.pagehelper.PageInfo;
import com.xunyin.common.service.impl.BaseServiceImpl;
import com.xunyin.common.utils.QueryHelpPlus;
import com.xunyin.modules.device.domain.TDevicePowerSet;
import com.xunyin.modules.device.service.TDevicePowerSetService;
import com.xunyin.modules.device.service.dto.TDeviceQueryCriteria;
import com.xunyin.modules.device.service.mapper.TDevicePowerSetMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


/**
 * @author xunyinyunshang
 * 硬件设备通断电设置Service实现
 * Created by xunyinyunshang <3594419785@qq.com>
 * CopyRight 讯音云商 https://www.tonetn.com
 * @date 2023-10-20
 */
@Service
@RequiredArgsConstructor
@Slf4j
//@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TDevicePowerSetServiceImpl extends BaseServiceImpl<TDevicePowerSetMapper, TDevicePowerSet> implements TDevicePowerSetService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    //@Cacheable
    public Map<String, Object> queryAll(TDeviceQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<TDevicePowerSet> page = new PageInfo<>(queryAll(criteria));
        Map<String, Object> map = new LinkedHashMap<>(2);
        map.put("content", page.getList());
        map.put("totalElements", page.getTotal());
        return map;
    }


    @Override
    //@Cacheable
    public List<TDevicePowerSet> queryAll(TDeviceQueryCriteria criteria) {
        return baseMapper.selectList(QueryHelpPlus.getPredicate(TDevicePowerSet.class, criteria));
    }
}
